<?php
namespace app\index\service;

use app\index\model\AcckuanModel;
use app\index\model\AccountListModel;
use app\index\model\AccountModel;
use app\index\model\DeptModel;
use app\index\model\HouChujinListModel;
use app\index\model\HouChushuiListModel;
use app\index\model\HouDayzhiListModel;
use app\index\model\HouGongshuiFuModel;
use app\index\model\HouGongzhiListModel;
use app\index\model\HouJieListModel;
use app\index\model\QianZhiListModel;
use app\index\model\TouJiaoListModel;
use think\Db;

class KuanService extends CommonService
{
    public function get_acckuan_paystate(){
        return [
            0 => '未支付',
            1 => '部分支付',
            2 => '全部支付',
        ];
    }
    public function get_acckuan_paystate_name($paystate=0){
        $arr = $this->get_acckuan_paystate();
        $str = isset($arr[$paystate]) ? $arr[$paystate] : '';
        return $str;
    }


    public function get_acckuan_modtype($type=1){
        if($type == 1){
            return [
                1 => '前期费收取-直营',
                2 => '工程回款',
                3 => '工程负责人预收款',
                4 => '保证金返还',
                5 => '日常收款',
                6 => '资金调拨(收入)',
                7 => '前期费收取-办事处',
            ];
        }elseif($type == 2){
            return [
                11 => '工程付款',
                12 => '前期费支付',
                13 => '投标保证金缴纳',
                14 => '费用报销',
                15 => '进项抵扣退税',
                16 => '储备进项支付',
                17 => '储备税费支付',
                18 => '借出款登记',
                19 => '日常付款',
                20 => '资金调拨(支出)',
            ];
        }else{
            return [
                1 => '前期费收取-直营',
                2 => '工程回款',
                3 => '工程负责人预收款',
                4 => '保证金返还',
                5 => '日常收款',
                6 => '资金调拨(收入)',
                7 => '前期费收取-办事处',

                11 => '工程付款',
                12 => '前期费支付',
                13 => '投标保证金缴纳',
                14 => '费用报销',
                15 => '进项抵扣退税',
                16 => '储备进项支付',
                17 => '储备税费支付',
                18 => '借出款登记',
                19 => '日常付款',
                20 => '资金调拨(支出)',
            ];
        }
    }
    public function get_acckuan_modtype_name($modtype=0){
        $arr = $this->get_acckuan_modtype(3);
        $str = isset($arr[$modtype]) ? $arr[$modtype] : '';
        return $str;
    }




    public function qian_shou($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 1;
        $ins['bidid'] = $minfo['bidid'];
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = '前期费收取-直营';
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['duier'];
        $ins['dt'] = $minfo['dt'];
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['accid'] = $minfo['accid'];
        $ins['explain'] = $minfo['explain'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        $kuanid = AcckuanModel::insertGetId($ins);

        $acclist = [];
        $acclist['comid'] = $this->userinfo['comid'];
        $acclist['kuanid'] = $kuanid;
        $acclist['modtype'] = 1;
        $acclist['jiaonum'] = (new IncomeService())->create_account_list_jiaonum_shou();
        $acclist['money'] = $ins['money'];
        $acclist['accid'] = $ins['accid'];
        $acclist['dt'] = $ins['dt'];
        $acclist['baner'] = $bill['flowuser'];
        $acclist['created_user'] = $ins['created_user'];
        $acclist['created_at'] = $ins['created_at'];
        AccountListModel::insert($acclist);

        return true;
    }
    public function hou_gonghui($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 2;
        $ins['bidid'] = 0;
        $ins['enginid'] = $minfo['enginid'];
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = (new OptService())->get_base_showname('cai_shougonglei', $minfo['shougonglei']);
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['duier'];
        $ins['dt'] = $minfo['dt'];
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['accid'] = $minfo['accid'];
        $ins['explain'] = $minfo['explain'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        $kuanid = AcckuanModel::insertGetId($ins);

        $acclist = [];
        $acclist['comid'] = $this->userinfo['comid'];
        $acclist['kuanid'] = $kuanid;
        $acclist['modtype'] = 2;
        $acclist['jiaonum'] = (new IncomeService())->create_account_list_jiaonum_shou();
        $acclist['money'] = $ins['money'];
        $acclist['accid'] = $ins['accid'];
        $acclist['dt'] = $ins['dt'];
        $acclist['baner'] = $bill['flowuser'];
        $acclist['created_user'] = $ins['created_user'];
        $acclist['created_at'] = $ins['created_at'];
        AccountListModel::insert($acclist);

        return true;
    }
    public function hou_gongyu($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 3;
        $ins['bidid'] = 0;
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = '工程负责人预收款';
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['duier'];
        $ins['dt'] = $minfo['dt'];
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['accid'] = $minfo['accid'];
        $ins['explain'] = $minfo['explain'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        $kuanid = AcckuanModel::insertGetId($ins);

        $acclist = [];
        $acclist['comid'] = $this->userinfo['comid'];
        $acclist['kuanid'] = $kuanid;
        $acclist['modtype'] = 3;
        $acclist['jiaonum'] = (new IncomeService())->create_account_list_jiaonum_shou();
        $acclist['money'] = $ins['money'];
        $acclist['accid'] = $ins['accid'];
        $acclist['dt'] = $ins['dt'];
        $acclist['baner'] = $bill['flowuser'];
        $acclist['created_user'] = $ins['created_user'];
        $acclist['created_at'] = $ins['created_at'];
        AccountListModel::insert($acclist);

        return true;
    }
    public function tou_fan($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 4;
        $ins['bidid'] = $minfo['bidid'];
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = (new OptService())->get_base_showname('cai_qishoulei', $minfo['qishoulei']);
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['shouer'];
        $ins['dt'] = $minfo['dt'];
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['accid'] = $minfo['accid'];
        $ins['explain'] = $minfo['explain'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        $kuanid = AcckuanModel::insertGetId($ins);

        $acclist = [];
        $acclist['comid'] = $this->userinfo['comid'];
        $acclist['kuanid'] = $kuanid;
        $acclist['modtype'] = 4;
        $acclist['jiaonum'] = (new IncomeService())->create_account_list_jiaonum_shou();
        $acclist['money'] = $ins['money'];
        $acclist['accid'] = $ins['accid'];
        $acclist['dt'] = $ins['dt'];
        $acclist['baner'] = $bill['flowuser'];
        $acclist['created_user'] = $ins['created_user'];
        $acclist['created_at'] = $ins['created_at'];
        AccountListModel::insert($acclist);

        return true;
    }
    public function hou_dayshou($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 5;
        $ins['bidid'] = 0;
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = (new OptService())->get_base_showname('cai_shouqilei', $minfo['shouqilei']);
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['shouer'];
        $ins['dt'] = $minfo['dt'];
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['accid'] = $minfo['accid'];
        $ins['explain'] = $minfo['explain'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        $kuanid = AcckuanModel::insertGetId($ins);

        $acclist = [];
        $acclist['comid'] = $this->userinfo['comid'];
        $acclist['kuanid'] = $kuanid;
        $acclist['modtype'] = 5;
        $acclist['jiaonum'] = (new IncomeService())->create_account_list_jiaonum_shou();
        $acclist['money'] = $ins['money'];
        $acclist['accid'] = $ins['accid'];
        $acclist['dt'] = $ins['dt'];
        $acclist['baner'] = $bill['flowuser'];
        $acclist['created_user'] = $ins['created_user'];
        $acclist['created_at'] = $ins['created_at'];
        AccountListModel::insert($acclist);

        return true;
    }
    public function account_shou($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 6;
        $ins['bidid'] = 0;
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = (new OptService())->get_base_showname('cai_shouqilei', $minfo['shouqilei']);
        $ins['money'] = $minfo['money'];
        $chuinfo = AccountModel::where(['id'=>$minfo['chuid']])->find();
        $ins['duier'] = DeptModel::where(['id'=>$chuinfo['chanid']])->value('name');
        $ins['dt'] = $minfo['dt'];
        $ins['incdaotype'] = '转账';
        $ins['accid'] = $minfo['ruid'];
        $ins['explain'] = $minfo['explain'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        $kuanid = AcckuanModel::insertGetId($ins);

        $acclist = [];
        $acclist['comid'] = $this->userinfo['comid'];
        $acclist['kuanid'] = $kuanid;
        $acclist['modtype'] = 6;
        $acclist['jiaonum'] = (new IncomeService())->create_account_list_jiaonum_shou();
        $acclist['money'] = $ins['money'];
        $acclist['accid'] = $ins['accid'];
        $acclist['dt'] = $ins['dt'];
        $acclist['baner'] = $bill['flowuser'];
        $acclist['created_user'] = $ins['created_user'];
        $acclist['created_at'] = $ins['created_at'];
        AccountListModel::insert($acclist);

        return true;
    }
    public function qian_ban($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 7;
        $ins['bidid'] = 0;
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = '前期费收取-办事处';
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['duier'];
        $ins['dt'] = $minfo['dt'];
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['accid'] = $minfo['accid'];
        $ins['explain'] = $minfo['explain'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        $kuanid = AcckuanModel::insertGetId($ins);

        $acclist = [];
        $acclist['comid'] = $this->userinfo['comid'];
        $acclist['kuanid'] = $kuanid;
        $acclist['modtype'] = 7;
        $acclist['jiaonum'] = (new IncomeService())->create_account_list_jiaonum_shou();
        $acclist['money'] = $ins['money'];
        $acclist['accid'] = $ins['accid'];
        $acclist['dt'] = $ins['dt'];
        $acclist['baner'] = $bill['flowuser'];
        $acclist['created_user'] = $ins['created_user'];
        $acclist['created_at'] = $ins['created_at'];
        AccountListModel::insert($acclist);

        return true;
    }





    public function hou_gongzhi($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = HouGongzhiListModel::where(['gongzhiid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 11;
            $ins['bidid'] = 0;
            $ins['enginid'] = $minfo['enginid'];
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhikuanlei', $item['zhikuanlei']);
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['bankzhang'] = $item['bankzhang'];
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function qian_zhi($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = QianZhiListModel::where(['zhiid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 12;
            $ins['bidid'] = $minfo['bidid'];
            $ins['enginid'] = 0;
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhiqianlei', $item['zhiqianlei']);
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function tou_jiao($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = TouJiaoListModel::where(['jiaoid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 13;
            $ins['bidid'] = $minfo['bidid'];
            $ins['enginid'] = 0;
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = '投标保证金缴纳';
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function hou_bao($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 14;
        $ins['bidid'] = 0;
        $ins['enginid'] = $minfo['enginid'];
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = '费用报销';
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['fuer'];
        $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
        $ins['bankzhang'] = $minfo['bankzhang'];
        $ins['banknum'] = $minfo['banknum'];
        $ins['bankname'] = $minfo['bankname'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        AcckuanModel::insert($ins);

        return true;
    }
    public function hou_gongshui22($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 15;
        $ins['bidid'] = 0;
        $ins['enginid'] = $minfo['enginid'];
        $ins['zhai'] = '进项抵扣退税';
        $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhiqilei', $minfo['zhiqilei']);
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['fuer'];
        $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $minfo['incdaotype']);
        $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
        $ins['banknum'] = $minfo['banknum'];
        $ins['bankname'] = $minfo['bankname'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        AcckuanModel::insert($ins);

        return true;
    }
    public function hou_gongshui($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = HouGongshuiFuModel::where(['gongshuiid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 15;
            $ins['bidid'] = 0;
            $ins['enginid'] = $minfo['enginid'];
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhiqilei', $minfo['zhiqilei']);
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['bankzhang'] = $item['bankzhang'];
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function hou_chujin($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = HouChujinListModel::where(['chujinid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 16;
            $ins['bidid'] = 0;
            $ins['enginid'] = 0;
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhiqilei', $minfo['zhiqilei']);
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function hou_chushui($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = HouChushuiListModel::where(['chushuiid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 17;
            $ins['bidid'] = 0;
            $ins['enginid'] = 0;
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhiqilei', $minfo['zhiqilei']);
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['bankzhang'] = $item['bankzhang'];
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function hou_jie22($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 18;
        $ins['bidid'] = 0;
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['yong'];
        $ins['kuanlei'] = '借出款';
        $ins['money'] = $minfo['money'];
        $ins['duier'] = $minfo['jieer'];
        $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
        $ins['incdaotype'] = (new OptService())->get_base_showname('cai_jie_fangtype', $minfo['fangtype']);
        $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
        $ins['banknum'] = $minfo['banknum'];
        $ins['bankname'] = $minfo['bankname'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        AcckuanModel::insert($ins);

        return true;
    }
    public function hou_jie($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = HouJieListModel::where(['jieid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 18;
            $ins['bidid'] = 0;
            $ins['enginid'] = 0;
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = '借出款';
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_jie_fangtype', $minfo['fangtype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['bankzhang'] = $item['bankzhang'];
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function hou_dayzhi($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id']])->find();
        if($exist){return true;}

        $list = HouDayzhiListModel::where(['dayzhiid'=>$minfo['id']])->select()->toArray();
        foreach ($list as $item){
            $ins = [];
            $ins['comid'] = $this->userinfo['comid'];
            $ins['billid'] = $bill['id'];
            $ins['mid'] = $minfo['id'];
            $ins['listid'] = $item['id'];
            $ins['modtype'] = 19;
            $ins['bidid'] = 0;
            $ins['enginid'] = 0;
            $ins['zhai'] = $item['explain'];
            $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhiqilei', $item['zhiqilei']);
            $ins['money'] = $item['money'];
            $ins['duier'] = $item['fuer'];
            $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
            $ins['incdaotype'] = (new OptService())->get_base_showname('cai_income_incdaotype', $item['incdaotype']);
            $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
            $ins['bankzhang'] = $item['bankzhang'];
            $ins['banknum'] = $item['banknum'];
            $ins['bankname'] = $item['bankname'];
            $ins['created_user'] = $minfo['created_user'];
            $ins['created_at'] = date('Y-m-d H:i:s');

            AcckuanModel::insert($ins);
        }

        return true;
    }
    public function account_zhi($bill, $minfo){
        $exist = AcckuanModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'billid'=>$bill['id'],'modtype'=>20])->find();
        if($exist){return true;}

        $ins = [];
        $ins['comid'] = $this->userinfo['comid'];
        $ins['billid'] = $bill['id'];
        $ins['mid'] = $minfo['id'];
        $ins['listid'] = 0;
        $ins['modtype'] = 20;
        $ins['bidid'] = 0;
        $ins['enginid'] = 0;
        $ins['zhai'] = $minfo['zhai'];
        $ins['kuanlei'] = (new OptService())->get_base_showname('cai_zhiqilei', $minfo['zhiqilei']);
        $ins['money'] = $minfo['money'];
        $ruinfo = AccountModel::where(['id'=>$minfo['ruid']])->find();
        $ins['duier'] = DeptModel::where(['id'=>$ruinfo['chanid']])->value('name');
        $ins['dt'] = date("Y-m-d", strtotime($minfo['created_at']));
        $ins['incdaotype'] = '转账';
        $ins['paystate'] = $ins['money'] > 0 ? 0 : 2;
        $ins['banknum'] = $ruinfo['name'].$ruinfo['accnum'];
        $ins['bankname'] = $ruinfo['accname'];
        $ins['created_user'] = $minfo['created_user'];
        $ins['created_at'] = date('Y-m-d H:i:s');
        AcckuanModel::insert($ins);

        return true;
    }













}
